package com.sias.beanpostprocessor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

/**
 * @author 吴文杰
 * @version 1.0
 * @since 2023/5/31 22:19
 */
@Component
public class Bean1 {
  private static final Logger log = LoggerFactory.getLogger(Bean1.class);


  private Bean2 bean2;

  @Autowired
  public void setBean2(Bean2 bean2) {
    log.debug("@Autowired生效:{}",bean2);
    this.bean2 = bean2;
  }

  @Autowired
  private Bean3 bean3;

  @Resource
  public void setBean3(Bean3 bean3) {
    log.debug("@Resource生效:{}",bean3);
    this.bean3 = bean3;
  }

  private String name;

  @Autowired
  public void setName(@Value("${JAVA_HOME}") String name) {
    log.debug("@Value生效:{}",name);
    this.name = name;
  }

  @PostConstruct
  public void init() {
    log.debug("@postConstruct 生效");
  }

  @PreDestroy
  public void destroy() {
    log.debug("@PreDestroy 生效");
  }

  @Override
  public String toString() {
    return "Bean1{" +
            "bean2=" + bean2 +
            ", bean3=" + bean3 +
            ", name='" + name + '\'' +
            '}';
  }
}
